<template>
  <el-card class="box-card">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item style="font-size: 16px">个人中心</el-breadcrumb-item>
      <el-breadcrumb-item style="font-size: 16px"
        >我的志愿表</el-breadcrumb-item
      >
    </el-breadcrumb>
    <div class="voluntaryForm">
      <!-- 本科一批 本科二批 高职高专 -->
      <div class="tab">
        <span
          v-for="(item, index) in typeList"
          @click="change(index)"
          class="tabChoose"
          :class="active === index ? 'active' : ''"
          ><span>{{ item.name }}</span
          ><span style="margin-left: 5px">{{ item.num }}</span
          >/9</span
        >
      </div>

      <el-card>
        <div class="container common flex space-between">
          <div class="tbody">
            <div>
              <div class="" style="">
                <ul class="thead flex">
                  <li class="num bo-rt">志愿序号</li>
                  <li class="name bo-rt">院校信息</li>
                  <li class="proNum bo-rt">专业序号</li>
                  <li class="proInfo bo-rt">专业信息</li>
                  <li class="do">操作</li>
                </ul>
              </div>
              <div style="display: none"></div>
            </div>
            <ul
              id="pro"
              class="tr bo-bm flex"
              v-for="(item, index) in resultList"
              :key="index"
            >
              <!-- 志愿几 -->
              <li class="num bo-rt flex align-items justify-content yell">
                <div
                  :style="{
                    color: item.name !== null ? 'rgba(255,101,0)' : '#666',
                  }"
                >
                  志愿<span>{{ item.wunId }}</span>
                </div>
              </li>
              <!-- 院校信息 -->
              <li class="name bo-rt flex align-items">
                <div
                  class="name flex justify-content flex-direction"
                  :style="{ display: item.name !== null ? 'block' : 'none' }"
                >
                  <div class="school flex align-items">
                    <div>
                      <div class="school-name flex">
                        <div class="code">{{ item.unvId }}</div>
                        <span class="overflow1">{{ item.name }}</span>
                      </div>
                      <div class="list flex">
                        <span class="item" v-if="item.is985 !== null">{{
                          item.is985
                        }}</span>
                        <span class="item" v-if="item.is211 !== null">{{
                          item.is211
                        }}</span>
                        <span class="item">{{ item.province }}</span>
                        <span class="item">{{ item.category }}</span>
                      </div>
                    </div>
                  </div>
                  <div class="flex">
                    <div
                      class="luqu-box flex align-items justify-content"
                      :class="{
                        bj_a1: item.probability < 50,
                        bj_a2: item.probability >= 50 && item.probability < 80,
                        bj_a3: item.probability >= 80,
                      }"
                    >
                      <div class="a1">
                        <div>
                          <div
                            class="chance"
                            v-if="item.probability < 50"
                            style="color: rgba(255, 97, 97)"
                          >
                            <span>{{ item.probability }}</span
                            >%
                            <div>可冲击</div>
                          </div>

                          <div
                            class="chance"
                            style="color: rgba(33, 193, 51)"
                            v-else-if="
                              item.probability >= 50 && item.probability < 80
                            "
                          >
                            <span>{{ item.probability }}</span
                            >%
                            <div>较稳妥</div>
                          </div>
                          <div
                            class="chance"
                            style="color: rgba(0, 182, 244)"
                            v-if="
                              item.probability >= 80 && item.probability < 100
                            "
                          >
                            <span>{{ item.probability }}</span
                            >%
                            <div>可保底</div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="plan">
                      <div>
                        招生人数
                        <span class="val">{{ item.num }}</span>
                      </div>
                      <div class="flex">
                        <span>{{ item.year }}</span
                        >年最低分/排名
                        <div class="val">
                          <span>{{ item.score }}</span
                          >/<span>{{ item.rank }}</span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </li>
              <!-- 专业几 -->
              <li
                class="
                  proNum
                  bo-rt
                  flex flex-direction
                  justify-content
                  align-items
                "
              >
                <div
                  class="proNum-item bo-bm flex justify-content align-items"
                  v-for="(major, majorIndex) in resultList[index].list"
                  :key="majorIndex"
                >
                  <div
                    :style="{
                      color: major.name !== null ? 'rgba(255,101,0)' : '#666',
                    }"
                  >
                    专业<span>{{ majorIndex + 1 }}</span>
                  </div>
                </div>
              </li>
              <!-- 专业信息 -->
              <li
                class="
                  proInfo
                  bo-rt
                  flex flex-direction
                  justify-content
                  align-items
                "
              >
                <div
                  class="proInfo-item bo-bm flex align-items"
                  v-for="(major, majorIndex) in item.list"
                  :key="majorIndex"
                >
                  <div class="mi-content flex align-items">
                    <div
                      class="majorInfo"
                      :style="{ display: major.name !== null ? '' : 'none' }"
                    >
                      <div class="majorName flex">
                        <!-- <div class="majorCode">
                          <span>{{ major.code }}</span>
                        </div> -->
                        <div class="overflow1" style="font-size: 15px">
                          {{ major.name }}
                        </div>
                      </div>
                      <p class="other flex">
                        <span class="mr flex"
                          >录取概率：
                          <span
                            class="val"
                            v-if="major.probability < 50"
                            style="color: rgba(255, 97, 97)"
                            >{{ major.probability }}%</span
                          >
                          <span
                            class="val"
                            v-if="
                              major.probability >= 50 && major.probability < 80
                            "
                            style="color: rgba(33, 193, 51)"
                            >{{ major.probability }}%</span
                          >
                          <span
                            class="val"
                            v-if="
                              major.probability >= 80 &&
                              major.probability <= 100
                            "
                            style="color: rgba(0, 182, 244)"
                            >{{ major.probability }}%</span
                          >
                        </span>
                        <!-- <span class="mr"
                          >2021招生数：<span class="val">{{
                            major.num
                          }}</span></span
                        > -->
                        <!-- <span class="mr"
                          >学费：<span class="val">{{
                            major.tuition
                          }}</span></span
                        > -->
                      </p>
                    </div>
                  </div>
                </div>
              </li>
              <!-- 相关操作 -->
              <li class="do flex justify-content align-items unselect">
                <div>
                  <button
                    class="update"
                    v-if="item.name !== null"
                    @click="updateChange(item.wunId, item.unvId)"
                  >
                    修改
                  </button>
                  <button
                    class="delete"
                    v-if="item.name !== null"
                    @click="deleteChange(item.wunId)"
                  >
                    删除
                  </button>
                  <button
                    class="add"
                    v-if="item.name === null"
                    @click="addChange"
                  >
                    添加
                  </button>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </el-card>
    </div>
  </el-card>
</template>

<script>
import qs from "qs";
import throttling from "@/public/throttling.js";
import Base64 from "base-64";
export default {
  name: "voluntaryForm",
  data() {
    return {
      // 选择批次
      active: 0,
      // 志愿批次 个数
      typeList: [
        {
          name: "本科一批",
          num: 6,
        },
        {
          name: "本科二批",
          num: 0,
        },
        {
          name: "高职专科批",
          num: 0,
        },
      ],
      // 志愿表批次
      resultList: [],
    };
  },
  methods: {
    // 切换批次志愿表
    change(index) {
      this.active = index;
      let name = this.typeList[this.active].name;
      console.log(name);
      this.$axios
        .get("/userWilling/" + this.typeList[this.active].name)
        .then((res) => {
          console.log(res);
          this.resultList = res.data;
        });
    },
    // 添加
    addChange() {
      this.$router.replace("/fillAspiration");
    },
    // 修改
    updateChange: throttling(function (wunId, unvId) {
      this.$axios.post(
        "/updateWilling",
        qs.stringify({
          formType: this.typeList[this.active].name,
          wunId: wunId,
        })
      );
      this.$router.push({
        name: "fillMajor",
        query: {
          unvId: unvId,
          formType: this.typeList[this.active].name,
        },
      });
    }, 200),
    // 删除
    deleteChange: throttling(function (wunId) {
      this.$axios
        .delete(
          "/deleteWilling/" + this.typeList[this.active].name + "/" + wunId
        )
        .then((res) => {
          this.$axios
            .get("/userWilling/" + this.typeList[this.active].name)
            .then((res) => {
              console.log(res);
              this.resultList = res.data;
            });
        });
    }, 200),
  },
  created() {
    const token = window.sessionStorage.getItem("tokenvalue");
    this.$axios.defaults.headers.common["satoken"] = token;
    this.$axios
      .get("/userWilling/" + this.typeList[this.active].name)
      .then((res) => {
        console.log(res);
        this.resultList = res.data;
      });
    this.$axios.get("getWillingNum").then((res) => {
      console.log(res);
      let typeNum = res.data;
      for (let i = 0; i < typeNum.length; i++) {
        this.typeList[i].num = typeNum[i];
      }
      console.log(this.typeList);
    });
  },
};
</script>

<style scoped>
li {
  list-style: none;
}

.el-card::-webkit-scrollbar {
  display: none;
}
.box-card {
  margin: 20px auto;
}
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
  float: left;
}

.voluntaryForm::-webkit-scrollbar {
  display: none;
}

.tab-sub-wrap {
  margin-top: 20px;
  width: 970px;
}

.tab {
  margin-top: 15px;
}

.tabChoose {
  height: 40px;
  width: 120px;
  padding: 5px 10px;
  display: inline-block;
  border-radius: 5px;
  text-align: center;
  line-height: 40px;
  border: 1px solid rgba(215, 215, 215);
}

.tabChoose:hover {
  cursor: pointer;
  background-color: rgba(255, 101, 0);
  border: 1px solid rgba(255, 101, 0);
  color: white;
  cursor: pointer;
}

.active {
  background-color: rgba(255, 101, 0);
  border: 1px solid rgba(255, 101, 0);
  color: white;
  cursor: pointer;
}

.oldStyle {
  border: 1px solid rgba(255, 101, 0);
  color: rgba(255, 101, 0);
}

.container {
  display: flex;
  justify-content: space-between;
  position: relative;
  width: 100%;
  z-index: 2;
  margin: 0 auto;
}

.tbody {
  width: 100%;
  min-height: 800px;
  font-size: 14px;
}

.thead {
  display: flex;
  width: 100%;
  height: 47px;
  line-height: 47px;
  background: #f4f4f4;
  border: 1px solid rgba(215, 215, 215);
  font-weight: bold;
  color: #333;
  text-align: center;
}

.bo-rt {
  border-right: 1px solid rgba(215, 215, 215);
}

.num {
  width: 100px;
  height: inherit;
}

.name {
  width: 300px;
  height: inherit;
}

.proNum {
  width: 95px;
  height: inherit;
}

.proInfo {
  width: 350px;
  height: inherit;
}

.protype {
  width: 80px;
  height: inherit;
}

.do {
  width: 100px;
  height: inherit;
}

.tr {
  display: flex;
  width: 100%;
  height: auto;
  border: 1px solid rgba(215, 215, 215);
  border-top: none;
}

.tr .proNum .yell,
.tr .yell {
  color: rgba(255, 101, 0);
}

.tr .num {
  width: 100px;
  height: inherit;
  font-size: 20px;
  font-weight: 400;
}

.align-items {
  align-items: center;
}

.justify-content {
  justify-content: center;
}

.flex {
  display: flex;
}

.tr .name {
  width: 300px;
  height: inherit;
  font-size: 14px;
  padding: 0 9px 0 10px;
}

.flex-direction {
  flex-direction: column;
}

.school .school-name {
  height: 20px;
  width: 300px;
  line-height: 20px;
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-bottom: 6px;
}

.school .code {
  padding: 0 5px;
  height: 20px;
  line-height: 20px;
  border-radius: 2px;
  text-align: center;
  background: rgba(17, 17, 17, 0.1);
  font-size: 12px;
  font-weight: 400;
  color: #333;
  margin-right: 6px;
  flex-shrink: 0;
}

.overflow1 {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.name .list {
  margin-top: 4px;
  min-width: 100px;
  border-radius: 2px;
  text-align: center;
  font-size: 12px;
  font-weight: 400;
  color: #555;
  margin-bottom: 5px;
}

.list .item {
  padding: 0 4px;
  border-right: none;
}

.name .luqu-box {
  width: 60px;
  height: 40px;
  border-radius: 6px;
  margin-right: 8px;
  text-align: center;
}

.bj_a1 {
  background-color: rgba(255, 97, 97, 0.1) !important;
}

.bj_a2 {
  background-color: rgba(229, 248, 254);
}

.bj_a3 {
  background-color: rgba(232, 249, 234);
}

.a1 {
  color: #ff6161;
}

.luqu-box .chance {
  font-size: 14px;
}

.luqu-box .status {
  font-size: 12px;
}

.plan {
  font-size: 14px;
  font-weight: 400;
  color: #999;
}

.plan .val {
  margin-left: 5px;
  color: #333;
}

.tr .proNum {
  width: 95px;
  height: inherit;
}

.proNum .proNum-item {
  height: 68px;
  width: 100%;
  font-size: 14px;
  font-weight: 400;
  color: #111;
}

.bo-bm {
  border-bottom: 1px solid rgba(215, 215, 215);
}

.tr .proInfo {
  width: 350px;
  height: inherit;
}

.proInfo .proInfo-item {
  height: 68px;
  width: 100%;
  overflow: hidden;
}

.proInfo-item .mi-content {
  width: 90%;
  margin-left: 8px;
}

.proInfo-item .majorInfo {
  width: 100%;
}

.majorName {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.proInfo-item .majorCode {
  min-width: 40px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 2px;
  margin-right: 6px;
  font-size: 14px;
  font-weight: 400;
  color: #333;
  flex-shrink: 0;
}

.proInfo-item .other {
  margin-top: 5px;
  font-size: 14px;
  font-weight: 400;
  color: #666;
}

.mr {
  margin-right: 8px;
}

.proInfo-item .other .val {
  color: #333;
}

.tr .protype {
  width: 80px;
  height: inherit;
}

.tr .do {
  width: 100px;
  height: inherit;
}

.do button {
  width: 68px;
  height: 30px;
  border-radius: 5px;
  background: #fff;
  line-height: 30px;
  font-size: 14px;
  font-weight: 400;
  text-align: center;
  margin: 5px 15px;
  cursor: pointer;
}

.update {
  border: 1px solid rgba(255, 101, 0);
  color: rgba(255, 101, 0);
}

.add {
  border: 1px solid rgba(0, 165, 38);
  color: rgba(0, 165, 38);
}

.delete {
  border: 1px solid rgba(236, 0, 0);
  color: rgba(236, 0, 0);
}
</style>